package com.zego.wawaji.ui.center.wawa;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zego.wawaji.R;
import com.zego.wawaji.base.module.ModuleMgr;
import com.zego.wawaji.base.utils.StringUtils;
import com.zego.wawaji.third.image.ImageLoader;
import com.zego.wawaji.ui.base.ExBaseAdapter;
import com.zego.wawaji.ui.bean.wawa.MyWawa;
import com.zego.wawaji.ui.bean.wawa.Wawa;

import java.util.List;

/**
 * 已申请发货
 * Created by Su on 2017/11/26.
 */
public class SendWawaAdapter extends ExBaseAdapter<MyWawa> {
    public SendWawaAdapter(Context context, List<MyWawa> datas) {
        super(context, datas);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder;
        if (convertView == null) {
            convertView = inflate(R.layout.my_wawa_send_item);
            holder = new MyViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyViewHolder) convertView.getTag();
        }
        final MyWawa info = getItem(position);
        Wawa wawa = ModuleMgr.getWawaMgr().getWawa(info.getWwTypeId());

        ImageLoader.loadRoundAvatar(getContext(), wawa.getImg(), holder.wawa_icon);
        holder.wawa_name.setText(wawa.getName());
        holder.time_info.setText(StringUtils.getCreateTime(info.getCreateTime()));
        holder.btn_follow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ModuleMgr.getWawaMgr().reqTransport(info.getTransPortID(),null);
            }
        });
        return convertView;
    }


    private class MyViewHolder {
        private ImageView wawa_icon;
        private TextView wawa_name, time_info;
        private RelativeLayout btn_follow;

        public MyViewHolder(View convertView) {
            initView(convertView);
        }

        private void initView(View convertView) {
            wawa_icon = (ImageView) convertView.findViewById(R.id.wawa_icon);
            wawa_name = (TextView) convertView.findViewById(R.id.wawa_name);
            time_info = (TextView) convertView.findViewById(R.id.time_info);
            btn_follow = (RelativeLayout) convertView.findViewById(R.id.btn_follow);
        }
    }
}
